# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :jwt_auth.py
# @Time      :2022/6/9 14:20
# @Author    :张志坤

# 前置登录
from flask import request, g
from common.utils.jwt_generate import check_jwt


def jwt_authorization():
    token = request.headers.get('Authorization')
    # print(token[7:])
    print('前置登录的token', token, type(token))
    if token:
        payload = check_jwt(token[7:])
        print("payload", payload)
        # 将用户id存入g对象
        if payload:
            g.user_id = payload.get('uid', None)
            print(111111111111111111)
            g.is_refresh = payload.get('is_refresh', False)
            print(g.is_refresh)
    else:
        print(2222222222222222)
        g.is_refresh = True
        g.user_id = ''
